import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http'
const authorization = window.localStorage.getItem('USER_TOKEN') ? JSON.parse(window.localStorage.getItem('USER_TOKEN')).token : ''
@Injectable({
  providedIn: 'root'
})
export class RequestService {
  baseUrl: string = 'http://190.168.1.192:3003'
  constructor(private http: HttpClient) { }

  get(url: string, params?: Object, options?: Object) {
    let param = new HttpParams()
    if (params) {
      for (const key in params) {
        if (params[key] === false || params[key]) {
          param = param.set(key, params[key])
        }
      }
    }
    return this.http.get(`${this.baseUrl}${url}`, {
      params: param,
      headers: {
        'authorization': authorization
      }
    })
  }
  post(url: string, data?: Object, options?: Object) {
    return this.http.post(`${this.baseUrl}${url}`, data, {
      headers: {
        'authorization': authorization
      }
    })
  }
  delete(url: string) {
    return this.http.delete(`${this.baseUrl}${url}`, {
      headers: {
        'authorization': authorization
      }
    })
  }
}
